<?php
/* 
* @Title:  [后台登陆控制器]
* @Author: {chenlei} [chenleib5@126.com]
* @Date:   2014-04-03 14:49:51
* @Last Modified by:   Administrator
* @Last Modified time: 2014-04-03 18:10:10
* @Copyright:  [hn7m.com]
*/
class LoginControl extends Control{
	/**
	 * [index 登陆界面]
	 * @return [type] [description]
	 */
	public function index(){
		if(IS_POST){
			$adminModel=K('Admin');  //加载后台用户模型

			if(!$adminModel->create()){	//执行自动验证
				$this->error($adminModel->error);
			}

			$name=Q('post.qname');		//接收填入的用户名/密码
			$password=Q('post.qpassword','','md5');

			$userData=$adminModel->where(array('qname'=>$name))->find(); //根据填入的用户名查找数据

			if(!$userData ||$password !=$userData['qpassword']){  //匹配用户失败
				$this->error('用户名或密码不正确!');
			}

			$_SESSION['qid']=$userData['qid'];   //匹配成功,存入SESSION
			$_SESSION['qname']=$userData['qname'];

			$this->success('恭喜您,登陆成功!',U('Index/index'));  //进入后台
		}

		$this->display();
	}

	public function Logout(){
		session('qid',NULL);
		session('qname',NULL);

		$this->success('退出成功!');
	}
}
?>